package javacafe.action.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javacafe.action.Action;
import javacafe.action.ActionForward;
import javacafe.dto.member.LoginInfoDTO;
import javacafe.service.MemberService;
import javacafe.serviceimple.MemberServiceImple;

public class LoginAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		ActionForward forward = new ActionForward();
		request.getSession().setAttribute("beforeURL", request.getRequestURI());
		
		MemberService memberService = MemberServiceImple.getInstance(); 
		
		String id = request.getParameter("m_id");
		String password = request.getParameter("m_password");
		
		LoginInfoDTO dto = memberService.getLoginInfo(id, password);
		
		
		if (dto != null) {
			request.getSession().setAttribute("loginInfo", dto);
//			forward.setTiles(false);
//			forward.setRedirect(true);
//			forward.setUrl((String)request.getSession().getAttribute("beforeURL"));
//			request.getSession().removeAttribute("beforeURL");
			forward.setUrl("index");
		} else {
			forward.setUrl("index");
		}
		
		return forward;
	}

}
